<!--
 *@Date: 2022-12-21 16:45:08
 * @LastEditTime: 2022-12-28 17:10:42
 *
 * @Description:
-->
<template>
    <uni-data-checkbox v-model="value" :localdata="range" @change="dataChange" :multiple="props.multiple"
        :map="{ text: 'mc', value: 'dm' }"></uni-data-checkbox>
</template>
<script setup lang="ts">
import { useDistStore } from '@/stores/modules/dist';
import { multiply } from 'lodash';
import { ref, watch } from 'vue';
const value = ref("" as string | string[])
const range = ref([] as any)
const props = defineProps({
    modelValue: {
        type: String,
    },
    zdlb: {
        type: String,
        required: true
    },
    multiple: {
        type: Boolean,
        default: false
    }
})

watch(() => props.modelValue, (newValue) => {
    if (newValue) {
        if (props.multiple) {
            value.value = newValue.split(",")
        } else {
            value.value = newValue

        }
    }
})

if (props.zdlb) {
    useDistStore().getDictList({ zdlb: props.zdlb }).then(result => {
        range.value = result
        if (props.modelValue) {
            if (props.multiple) {
                value.value = props.modelValue.split(",")
            } else {
                value.value = props.modelValue
            }
        }
    })
}

const emits = defineEmits(['update:modelValue']);
const dataChange = (e: any) => {
    if (props.multiple) {
        emits('update:modelValue', e.join(","))
    } else {
        emits('update:modelValue', e)
    }
}

</script>
<style lang="scss" scoped>

</style>
